package com.ffzx.commerce.framework.beans;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * 类属性为空断言
 * 
 * @author zhugj
 * @date 2014年9月11日 下午3:05:55
 * @version 0.1.0 
 */
public class BeanPropertyNullPredicate extends CustomPredicate {

	private String propertyName;
	
	public BeanPropertyNullPredicate(String propertyName) {
		this.propertyName = propertyName;
	}
	@Override
	public boolean evaluate(Object bean) {
		try {
			Object another = PropertyUtils.getProperty(bean, propertyName);
			if (another != null) {
				return StringUtils.isBlank(another.toString());
			} 
			return another == null;
		} catch (Exception ex) {
			throw new IllegalArgumentException(ex);
		}
	}

}
